class Game < ApplicationRecord
  enum propose: [:win, :lose, :big, :small, :one, :two]

  enum state: [:pending, :winned, :losed, :winned_half, :losed_half, :tie]

  belongs_to :master, class_name: "Team", foreign_key: "master_id"
  belongs_to :guest, class_name: "Team", foreign_key: "guest_id"
  belongs_to :league_game

  has_many :bets, dependent: :destroy

  def approve
    approve = "计划：#{self.master_or_guest ? self.master.name : self.guest.name} #{i18n_enum(self, :propose)}"
  end

  def i18n_enum model, type
    I18n.t "#{model.class.model_name.i18n_key}.#{type}.#{model.send(type)}" if model.respond_to?(type)
  end
  
end
